package com.hq.zb.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.hq.zb.dto.CustomerInfoDto;
import com.hq.zb.service.ICustomerInfoService;
import com.hq.zb.utils.Result;
import com.hq.zb.vo.CustomerInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 客户基本信息 前端控制器
 * </p>
 *
 * @author huanghanrui
 * @since 2022-03-24
 */
@RestController
@RequestMapping("/cus")
public class CustomerInfoController {
    @Autowired
    private ICustomerInfoService customerInfoService;

    /**
     * 保存客户基本信息
     * @param customerInfoDto
     * @return
     */
    @PostMapping("/customer/save")
    public Result saveCustomerInfo(@RequestBody CustomerInfoDto customerInfoDto) {
        customerInfoService.saveCustomerInfo(customerInfoDto);
        return Result.ok();
    }

    /**
     * 查询客户基本信息(分页)
     * @param dto 参数
     * @param pageNum 页
     * @param pageSize 页大小
     * @return
     */
    @PostMapping("/code/query")
    @ResponseBody
    public Result queryCustomerInfo(@RequestBody CustomerInfoDto dto, int pageNum, int pageSize) {
        Page<CustomerInfoVo> page = new Page<>(pageNum, pageSize);
        Page<CustomerInfoVo> list = customerInfoService.queryCustomerInfo(page, dto);
        return Result.data(list);
    }
}

